<template>
  <div class="container-page container-page-banner-list">
    <el-table border :data="list" size="mini" :lazy="true">
      <el-table-column align="center" width="380" label="图片">
        <template slot-scope="props">
          <el-image class="item-image" :src="props.row.img" fit="cover" />
        </template>
      </el-table-column>
      <el-table-column align="center" prop="link" label="跳转链接" />
      <el-table-column align="center" label="添加时间">
        <template slot-scope="props">
          <span class="el-icon-date"> {{ new Date(props.row.created_at) | parseTime('{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作">
        <template slot-scope="props">
          <el-button size="mini" plain class="el-icon-delete" type="danger" @click="deleteBanner(props.row.id)" />
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getBanner, deleteBanner } from '@/api/miva';
export default {
  data() {
    return {
      list: []
    };
  },
  async mounted() {
    await this.getBanner();
  },
  methods: {
    //   获取轮播图列表
    async getBanner() {
      const res = await getBanner();
      this.list = res.data;
    },
    // 删除轮播图
    async deleteBanner(id) {
      this.$confirm('确认删除嘛?', {
        confirmButtonText: '确认',
        cancelButtonText: '取消'
      }).then(async() => {
        await deleteBanner({ id });
        await this.getBanner();
      }).catch(() => {});
    }
  }
};
</script>

<style lang="scss" scoped>
.item-image {
    width: calc(1600px * .2);
    height: calc(900px *.2);
}
</style>
